﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZP.Common;
using ZP.DTO.Common;
using ZP.DTO.ep_base_info;
using ZP.DTO.ep_business_product;
using ZP.DTO.ep_gov_support;
using ZP.DTO.ep_investor;
using ZP.DTO.ep_personnel_info;
using ZP.DTO.ht_honor_title;
using ZP.IBLL;

namespace ZPJWeb.Controllers
{
    public class EnterpriseController : BaseController
    {
        //public EnterpriseController(Iep_base_infoService _ep_base_infoService)
        //{
        //    this._ep_base_infoServic = _ep_base_infoService;
        //}

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetEnterprise()
        {
            ResultData<ep_base_infoResultDTO> resultData = new ResultData<ep_base_infoResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    resultData.Object = _ep_base_infoServic.GetEnterprise(ep_id);
                    resultData.SubmitResult = true;
                }
                else
                {
                    resultData.Message = TipsMessage.请登录后再试;
                }
            }
            catch (Exception e)
            {
                resultData.Exception = e;
                resultData.Message = e.Message;
            }
            return Json(resultData, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 保存企业信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult SaveEnterprise(ep_base_infoOperateDTO dto)
        {
            ResultData<ep_base_infoResultDTO> resultData = new ResultData<ep_base_infoResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    dto.ep_id = ep_id;
                    resultData.SubmitResult = _ep_base_infoServic.SaveEnterprise(dto);
                }
            }
            catch (Exception e)
            {
                resultData.Exception = e;
                resultData.Message = e.Message;
            }
            return Json(resultData, JsonRequestBehavior.AllowGet);

        }

        public JsonResult GetEnterpriseInvestor()
        {
            //ResultData<List<ep_investorResultDTO>> resultData = new ResultData<List<ep_investorResultDTO>>();
            PageModel<ep_investorResultDTO> pageList = new PageModel<ep_investorResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    pageList.data = _ep_investorService.GetEnterpriseInvestor(ep_id);
                }
                else
                {
                    pageList.msg = TipsMessage.请登录后再试;
                }
            }
            catch (Exception e)
            {
                pageList.code = -99;
                pageList.msg = e.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetEnterpriseProduct()
        {
            PageModel<ep_business_productResultDTO> pageList = new PageModel<ep_business_productResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    pageList.data = _ep_business_productService.GetEnterpriseProduct(ep_id);
                }
                else
                {
                    pageList.msg = TipsMessage.请登录后再试;
                }
            }
            catch (Exception e)
            {
                pageList.code = -99;
                pageList.msg = e.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetEnterprisePersonnalInfo()
        {
            PageModel<ep_personnel_infoResultDTO> pageList = new PageModel<ep_personnel_infoResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    pageList.data = _ep_personnel_infoService.GetEnterprisePersonnalInfo(ep_id);
                }
                else
                {
                    pageList.msg = TipsMessage.请登录后再试;
                }
            }
            catch (Exception e)
            {
                pageList.code = -99;
                pageList.msg = e.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetEnterpriseSupportInfo()
        {
            PageModel<ep_gov_supportResultDTO> pageList = new PageModel<ep_gov_supportResultDTO>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    pageList.data = _ep_gov_supportService.GetEnterpriseSupportInfo(ep_id);
                }
                else
                {
                    pageList.msg = TipsMessage.请登录后再试;
                }
            }
            catch (Exception e)
            {
                pageList.code = -99;
                pageList.msg = e.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }
        


        public JsonResult GetEnterpriseZPJScore()
        {
            ResultData<List<EnterpriseHonorScoreResultDTO>> resultData = new ResultData<List<EnterpriseHonorScoreResultDTO>>();
            try
            {
                //根据登录信息获得ep_id
                if (Session[ZPCommon.SESSION_Portal_Login] != null)
                {
                    PortalUserLoginDTO loginUser = (PortalUserLoginDTO)Session[ZPCommon.SESSION_Portal_Login];
                    int ep_id = loginUser.user_id;
                    resultData.Object = _ep_base_infoServic.GetEnterpriseZPJScore(ep_id);
                    resultData.SubmitResult = true;
                }
            }
            catch (Exception e)
            {
                resultData.Exception = e;
                resultData.Message = e.Message;
            }
            return Json(resultData);
        }
    }
}